﻿#include <iostream>
#include <math.h>
int getReverse(int index) {
	int temp,remainder,order = 0;
	int indextemp = index;
	int result = 0;
	do 
	{
		index /= 10;
		order++;
	} while (index!= 0);
	for (temp = 1; temp <= order; temp++)
	{
	
		remainder= indextemp % 10;
		indextemp /= 10;
		result += remainder * (int)pow(10, order - temp );
	}
	return result;
}
//
double getCnmLg(int n, int m)
{
	int i;
	double s1 = 0.0, s2 = 0.0;
	for (i = 1; i <= m; i++)
		s1 += log(i);
	for (i = n - m + 1; i <= n; i++)
		s2 += log(i);
	return s2 - s1;
}

double getCnmDouble(int n, int m)
{
	if (m > n / 2)
		m = n - m;
	return exp(getCnmLg(n, m));
}
int getNumber(int num) {
	int even, temp, result = 0;
	if (num % 2 == 0)
	{
		even = num / 2;
		for (temp = 0; temp <= even; temp++)
		{				
				int mm = temp;
				int nn = (num - 2 * temp + temp);
				result += getCnmDouble(nn, mm);			
		}
	}
	if (num % 2 != 0)
	{
		even = (num - 1) / 2;
		for (temp = 0; temp <= even; temp++)
		{
				int mm = temp;
				int nn = (num - 2 * temp + temp);
				result += getCnmDouble(nn, mm);	
		}
	}
	return result;
}
int main() {
	int result1 = getReverse(4321);
	std::cout << result1 << std::endl;
	int result2 = getNumber(4);
	std::cout << result2 << std::endl;
	return 0;
}